﻿//-----------------------------------------------------------------------
// <copyright>
// This file is subject to the terms and conditions of the Microsoft Public License (MS-PL).
// See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL for more details.
// </copyright>
//----------------------------------------------------------------------- 
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Xml.Linq;

namespace Fulcrum.ViewModelGenerator.UnitTests
{
    [TestClass]
    public class ViewModelGenerationDataContextTests
    {
        public ViewModelGenerationDataContextTests()
        {
            // nothing
        }

        IViewModelCollectionConfig viewModelCollection;
        IViewModelConfiguration viewModelConfig;
        ViewModelGenerationDataContext dataContext;

        [TestInitialize]
        public void TestInitialize()
        {
            this.viewModelCollection = new ViewModelCollectionXmlConfig(XmlHelper.CreateMinimalViewModelCollection());

            var viewModelXml = XmlHelper.CreateMinimalViewModel("MyViewModelClass");
            viewModelXml.Add(new XAttribute("Location", "MyDir"));
            this.viewModelConfig = new ViewModelXmlConfiguration(viewModelXml);

            this.dataContext = new ViewModelGenerationDataContext(this.viewModelCollection, this.viewModelConfig);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ViewModelGenerationDataContext_Ctor_NullCollection()
        {
            var myDataContext = new ViewModelGenerationDataContext(null, this.viewModelConfig);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ViewModelGenerationDataContext_Ctor_NullViewModel()
        {
            var myDataContext = new ViewModelGenerationDataContext(this.viewModelCollection, null);
        }

        [TestMethod]
        public void ViewModelGenerationDataContext_Collection()
        {
            Assert.AreSame(this.viewModelCollection, this.dataContext.Collection);
        }

        [TestMethod]
        public void ViewModelGenerationDataContext_Name()
        {
            Assert.AreEqual("MyViewModelClass", this.dataContext.Name);
        }

        [TestMethod]
        public void ViewModelGenerationDataContext_OutputFileName()
        {
            Assert.AreEqual("MyViewModelClass.Generated", this.dataContext.OutputFileName);
        }

        [TestMethod]
        public void ViewModelGenerationDataContext_OutputPath()
        {
            Assert.AreEqual("MyDir", this.dataContext.OutputPath);
        }

        [TestMethod]
        public void ViewModelGenerationDataContext_TemplateFileName()
        {
            Assert.AreEqual("ViewModel.t4", this.dataContext.TemplateFileName);
        }

        [TestMethod]
        public void ViewModelGenerationDataContext_ViewModel()
        {
            Assert.AreSame(this.viewModelConfig, this.dataContext.ViewModel);
        }

    }
}
